package com.xsz.pda.data.db

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.xsz.pda.data.bean.CheckRecord

@Dao
interface CheckRecordDao {

    @Insert
    fun insert(checkRecord: CheckRecord)

    @Update
    fun updateRecords(checkRecords: List<CheckRecord>)

    @Update
    fun updateRecord(checkRecords: CheckRecord)

    @Query("select * from checkrecord where status=0 order by checkTime limit 15")
    fun findNotSynced(): List<CheckRecord>

    @Query("select * from checkrecord where status=1 order by checkTime limit 1")
    fun findNotUploadPic(): CheckRecord?

    @Query("select count(id) from checkrecord")
    fun countRecord():Int

    @Query("delete from checkrecord where ticketItemId = :ticketItemId")
    fun deleteByTicketId(ticketItemId: String)

    @Query("delete from checkrecord")
    fun clear()

    @Query("select * from checkrecord where id=:id")
    fun queryById(id: String): CheckRecord?

    @Query("select timestamp from checkrecord order by timestamp desc limit 1")
    fun getLastSyncTime(): Long?

    @Query("select * from checkrecord where ticketItemId in (:itemIds) order by checkTime desc limit 1")
    fun getLastCheck(itemIds: List<String>): CheckRecord?


    @Query("select count(1) from checkrecord where checkTime >= :start and checkTime <= :end")
    fun getCheckCountToday(start: String, end: String):Int

}